import static java.lang.Math.sqrt
public class PrimeNumberPrinter {
    private static final int MAX_NUMBER = 20000;
    private static final int NUMBERS_PER_LINE = 5;
    public static boolean isPrime(int num) {
        if (num <= 1) {
            return false;
        }
        if (num <= 3) {
            return true;
        }
        if (num % 2 == 0 || num % 3 == 0) {
            return false;
        }
        for (int i = 5; i <= sqrt(num); i += 6) {
            if (num % i == 0 || num % (i + 2) == 0) {
                return false;
            }
        }
        return true;
    }
    public static void main(String[] args) {
        int count = 0;
        System.out.println("1到" + MAX_NUMBER + "之间的素数如下：");
        for (int i = 1; i <= MAX_NUMBER; i++) {
            if (isPrime(i)) {
                System.out.printf("%6d ", i);
                count++;
                if (count % NUMBERS_PER_LINE == 0) {
                    System.out.println();
                }
            }
        }   System.out.println("\n==================================");
        System.out.println("共找到 " + count + " 个素数");
    }
}